//
//  WDCarListCellTableViewCell.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/21.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDCarListCell.h"
#import "WDCarList.h"

@interface WDCarListCell ()
/** 车标 */
@property (nonatomic, weak) UIImageView *iconView;
/** 车品牌名 */
@property (nonatomic, weak) UILabel *nameLabel;
@end

@implementation WDCarListCell

+ (instancetype)carListCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"carListCell";
    WDCarListCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        UIImageView *iconView = [[UIImageView alloc] init];
        [self.contentView addSubview:iconView];
        self.iconView = iconView;
        
        [iconView makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(10);
            make.centerY.equalTo(self.contentView.centerY);
            make.width.equalTo(WDScale(50));
            make.height.equalTo(WDScale(35));
        }];
        
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.font = [UIFont systemFontOfSize:14];
        nameLabel.textColor = ColorForRGB(0x6d6d6d);
        [self.contentView addSubview:nameLabel];
        self.nameLabel = nameLabel;
        
        [nameLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(iconView.right).offset(16);
            make.centerY.equalTo(self.contentView.centerY);
        }];
    }
    return self;
}

- (void)setCarList:(WDCarList *)carList
{
    _carList = carList;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:carList.url] placeholderImage:[UIImage imageWithColor:ColorForRGB(0xf1f1f1)]];
    self.nameLabel.text = carList.name;
}

@end
